package com.mfoyou.agent.web.service.wx;

import java.net.SocketTimeoutException;
import java.util.HashMap;

import org.apache.http.conn.ConnectTimeoutException;
import org.mfoyou.agent.utils.common.HttpsUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.boyuanitsm.pay.alipay.util.httpClient.HttpRequest;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.io.xml.XmlFriendlyNameCoder;

@Service
public class PayService {

    public HashMap<Integer, HttpRequest> hashMap = new HashMap<>();

    public static final String payurl = "https://api.mch.weixin.qq.com/pay/unifiedorder";
    public static final String revokeUrl = "https://api.mch.weixin.qq.com/secapi/pay/refund";

    public String post(Object object) throws Exception {
        return HttpsUtils.postXml(payurl, obj2xml(object));
    }

    public String obj2xml(Object object) {
        XStream xStreamForRequestPostData = new XStream(new DomDriver("UTF-8", new XmlFriendlyNameCoder("-_", "_")));
        //将要提交给API的数据对象转换成XML格式数据Post给API
        String postDataXML = xStreamForRequestPostData.toXML(object);
        return postDataXML;
    }

}
